#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *my_strcpy(char *dest, const char *src) {
  int i = 0;
  for (i = 0; src[i] != '\0'; i++) {
    dest[i] = src[i];
  }
  dest[i] = '\0';
  return dest;
}

void unique_zero(int *nums, size_t n) {
  int *temp = malloc(n * sizeof(int));
  int count = 0;

  for (size_t i = 0; i < n; i++) {
    if (nums[i] != 0) {
      temp[count++] = nums[i];
    }
  }
  while (count < n) {
    temp[count++] = 0;
  }

  memcpy(nums, temp, n * sizeof(int));
  free(temp);
}

char *str_reverse(const char *s) {
  int len = strlen(s);
  char *ret = malloc(len + 1);
  if (ret == NULL) {
    return NULL;
  }
  for (int i = 0; i < len; i++) {
    ret[i] = s[len - 1 - i];
  }
  ret[len] = '\0';
  return ret;
}

int main() {
  char str[] = {'h', 'e', 'l', 'l', 'o', '\0'};
  char cpy[10];
  my_strcpy(cpy, str);
  puts(cpy);

  int nums[] = {5, 6, 0, 4, 6, 0, 6};
  unique_zero(nums, 7);
  for (int i = 0; i < 7; i++) {
    printf("%d  ", nums[i]);
  }
  printf("\n");

  char *rev = str_reverse(str);
  if (rev != NULL) {
    puts(rev);
    free(rev);
  }

  return 0;
}
